#!/bin/bash

# Usage scenario:
#   user1: tm xx
#   user2: tm xx
#   user3: tm xx
# where "xx" can be any other session name.

session=$1
[[ $session ]] || session=pair

[[ -d /tmp/tmux ]] || {
	mkdir /tmp/tmux
	chown .team /tmp/tmux
}

sock=/tmp/tmux/$session.sock

if tmux -S /tmp/tmux/$session.sock ls 2>/dev/null; then
	tmux -f /etc/tm.conf -S $sock attach -t $session
else
	tmux -f /etc/tm.conf -S $sock new-session -s $session "chgrp team $sock; zsh"
fi
